package game;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;

public class Sprite extends GameObject {

	private static final long serialVersionUID = 1L;
	private Image image;
	private BufferedImage bf;
	
	public Sprite(int index, Point2D position, Point2D dimension)
	{
		super (index, position, dimension);
		
		this.image = LoadImage.GetInstance().textures.get(index);
		bf = new BufferedImage((int)dimension.getX(), (int)dimension.getY(), BufferedImage.TYPE_INT_ARGB);
	}
	
	//Draw for sprites without animation
	public void draw(Graphics g)
	{
		bf.createGraphics().drawImage(image, 0, 0, (int)this.dimension.getX(), (int)this.dimension.getY(), this);
		super.setImage(bf);
		super.draw(g);
	}
	
	//Draw for Animated Sprites
	public void draw(Graphics g, Point2D sP, Point2D sD)
	{
		bf = new BufferedImage((int)this.dimension.getX(),(int) this.dimension.getY(), BufferedImage.TYPE_INT_ARGB);
		bf.createGraphics().drawImage(image, 0, 0, (int)this.dimension.getX(), (int)this.dimension.getY(),
								   (int)sP.getX(), (int)sP.getY(), 
								   (int)sP.getX() + (int)sD.getX(), 
								   (int)sP.getY() + (int)sD.getY(), this);
		super.setImage(bf);
		super.draw(g);
	}
}
